package com.henu.action;

import java.util.List;

import org.smart4j.framework.ioc.annotation.Inject;
import org.smart4j.framework.mvc.annotation.Action;
import org.smart4j.framework.mvc.annotation.Request;
import org.smart4j.framework.mvc.bean.Params;
import org.smart4j.framework.mvc.bean.View;

import com.henu.service.CategoryService;
import com.henu.util.DwzResult;

@Action
public class CategoryAction {
    @Inject
    private CategoryService categoryService;

    @org.smart4j.framework.mvc.annotation.Request.Get("/Product/GetCategory")
    public View getCategory() {
        List categeroy = categoryService.getCategorys();
        return new View("category.jsp").data("category",categeroy );
    }

    @Request.Post("/Category/Add")
    public DwzResult addCategory(Params params) {
        String categoryName = params.getString("categoryName");
        String categoryContent = params.getString("categoryContent");
        String imageUrl = params.getString("imageUrl");
        categoryService.insertCategory(categoryName, categoryContent, imageUrl);
        return DwzResult.buildCloseCurent();
    }

    @Request.Post("/Category/Del")
    public DwzResult delCategory(Params params) {
        Integer id = params.getInt("id");
        categoryService.deleteCategoryByID(id);
        return DwzResult.buildSuccess();
    }

    @Request.Post("/Category/Update")
    public DwzResult updateCategory(Params params) {
        Integer id = params.getInt("id");
        String categoryName = params.getString("categoryName");
        String categoryContent = params.getString("categoryContent");
        String imageUrl = params.getString("imageUrl");
        categoryService.updateCategory(id, categoryName, categoryContent, imageUrl);
        return DwzResult.buildCloseCurent();
    }
}
